﻿
@{
    ViewData["Title"] = "LogList";
    Layout = "~/Areas/Admin/Views/_Layout.cshtml";
}
<table class="layui-hide" id="tabledata" lay-filter="tabledata"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        @Html.Raw(Mrc.Application.PermissionButtonHelper.CreateButtonHtml(new List<string> { "system.ipfilter.add", "system.ipfilter.update", "system.ipfilter.delete" }, ViewContext.HttpContext));
        <button class="layui-btn layui-btn-sm" onclick="javascript:location.replace(location.href);">刷新</button>
    </div>
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#tabledata'
                , height: 'full-20'
                , url: '/admin/ipfilter/GetIPFilterData'
                , toolbar: '#toolbarDemo'
                , title: 'IP过滤'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'startIP', title: 'IP', fixed: 'left', unresize: true, sort: true }
                    , 
                    {
                        field: 'isEnable', title: '是否启用', width: 350, templet: function (res){
                            return  enableSwitch(res.isEnable);
                        }
                    }
                    //, { field: 'CreateTime', title: '创建时间' }
                    , { field: 'description', title: '描述' }
                ]]
                , limits: [10, 15, 40, 60, 80,100,200,400]
                , limit: 100 //默认采用10
                , page: true
                , request: {
                    pageName: 'pageNumber' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
            });

            //头工具栏事件
            table.on('toolbar(tabledata)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'add':
                        x_admin_show("添加过滤IP", "/admin/ipfilter/add",550,400);   
                        break;
                    case 'update':
                        var data = checkStatus.data;
                        if (data.length > 1)
                        {
                            layer.msg('请选择单个编辑项');
                            break;
                        }
                        else
                        {                    
                            var thisline = data[0];
                            var id = thisline.id;
                            x_admin_show("添加过滤IP", "/admin/ipfilter/update?Id=" + id, 550, 400); 
                        }                      
                        break;
                    case 'delete':
                        var data = checkStatus.data;
                        if (data.length > 1)
                        {
                            layer.msg('请选择删除项');
                            break;
                        }
                        else
                        {
                            var ids = [];
                            for (var i = 0; i < data.length; i++)
                            {
                                ids.push(data[i].id);
                            }
                            BaseAjax(ajaxType.post, "/admin/ipfilter/delete", { ids: ids }, function (repo) {
                                if (repo.status == ajaxStatus.OK)
                                {
                                    table.reload('tabledata', { page: { curr: 1 }});
                                }
                            });
                        }
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;
                };
            });
        });
        function enableSwitch(isenable)
        {
            return isenable ? '<span style="color:red">开启</span>' : "未启用";
        }
</script>

